package cn.imu.appdevexperiment2020._2activity;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import cn.imu.appdevexperiment2020.R;
import cn.imu.appdevexperiment2020._2activity.adapter.FruitRecAdapter;
import cn.imu.appdevexperiment2020._2activity.bean.Fruit;
import cn.imu.appdevexperiment2020.common.BaseActivity;

/**
 * 描述:
 *
 * @author chenconghua
 * @version 1.0
 * @create 2022-11-05 17:34
 */
public class RecyclerViewActivity extends BaseActivity {

    @BindView(R.id.rec_view)
    RecyclerView recyclerView;

    private List<Fruit> fruitList =new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recyclerview);
        initFruits();
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);
        FruitRecAdapter adapter=new FruitRecAdapter(fruitList);
        recyclerView.setAdapter(adapter);
    }

    private void initFruits() {
        Fruit apple = new Fruit("Apple",R.drawable.apple_pic);
        fruitList.add(apple);
        Fruit pear = new Fruit("Pear",R.drawable.pear_pic);
        fruitList.add(pear);
        Fruit pineapple = new Fruit("Pineapple",R.drawable.pineapple_pic);
        fruitList.add(pineapple);
        Fruit banana = new Fruit("Banana",R.drawable.banana_pic);
        fruitList.add(banana);
        Fruit grape = new Fruit("Grape",R.drawable.grape_pic);
        fruitList.add(grape);
        Fruit mango = new Fruit("Mango",R.drawable.mango_pic);
        fruitList.add(mango);
        Fruit orange = new Fruit("Orange",R.drawable.orange_pic);
        fruitList.add(orange);
    }
}
